def prost(n):
    c = True
    if len(str(n)) != 3:
        c = False
    for d in range(2, int(n ** 0.5) + 1):
        if n % d == 0:
            c = False
            break
    return c

a = input()
n = a.split()
dig = {'one': 1,
       'two': 2,
       'three': 3,
       'four': 4,
       'five': 5,
       'six': 6,
       'seven': 7,
       'eight': 8,
       'nine': 9,
       'zero': 0}
if len(n) != 3 or not (set(n) <= set(dig.keys())):
    print('Wrong input')
    exit()

n = dig[n[0]] * 100 + dig[n[1]] * 10 + dig[n[2]]
if prost(n):
    print(n)
else:
    pr = n
    while not prost(pr):
        pr += 1
    pl = n
    while not prost(pl):
        pl -= 1
    if abs(n - pr) >= abs(n - pl):
        print(pl)
    else:
        print(pr)
